<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Executors</title>
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../../boost_asio.html" title="Boost.Asio">
<link rel="up" href="../model.html" title="Asynchronous Model">
<link rel="prev" href="child_agents.html" title="Child Agents">
<link rel="next" href="allocators.html" title="Allocators">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
<td align="center"><a href="../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="child_agents.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../model.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../boost_asio.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="allocators.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="boost_asio.overview.model.executors"></a><a class="link" href="executors.html" title="Executors">Executors</a>
</h4></div></div></div>
<p>
          Every asynchronous agent has an associated <span class="emphasis"><em>executor</em></span>.
          An agent's executor determines how the agent's completion handlers are
          queued and ultimately run.
        </p>
<p>
          Example uses of executors include:
        </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
              Coordinating a group of asynchronous agents that operate on shared
              data structures, ensuring that the agents' completion handlers never
              run concurrently<a href="#ftn.boost_asio.overview.model.executors.f0" class="footnote" name="boost_asio.overview.model.executors.f0"><sup class="footnote">[5]</sup></a>.
            </li>
<li class="listitem">
              Ensuring that agents are run on specified execution resource (e.g.
              a CPU) that is proximal to data or an event source (e.g. a NIC).
            </li>
<li class="listitem">
              Denoting a group of related agents, and so enabling dynamic thread
              pools to make smarter scheduling decisions (such as moving the agents
              between execution resources as a unit).
            </li>
<li class="listitem">
              Queuing all completion handlers to run on a GUI application thread,
              so that they may safely update user interface elements.
            </li>
<li class="listitem">
              Returning an asynchronous operation's default executor as-is, to run
              completion handlers as close as possible to the event that triggered
              the operation's completion.
            </li>
<li class="listitem">
              Adapting an asynchronous operation's default executor, to run code
              before and after every completion handler, such as logging, user authorisation,
              or exception handling.
            </li>
<li class="listitem">
              Specifying a priority for an asynchronous agent and its completion
              handlers.
            </li>
</ul></div>
<p>
          The asynchronous operations within an asynchronous agent use the agent's
          associated executor to:
        </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
              Track the existence of the work that the asynchronous operation represents,
              while the operation is outstanding.
            </li>
<li class="listitem">
              Enqueue the completion handler for execution on completion of an operation.
            </li>
<li class="listitem">
              Ensure that completion handlers do not run re-entrantly, if doing so
              might lead to inadvertent recursion and stack overflow.
            </li>
</ul></div>
<p>
          Thus, an asynchronous agent's associated executor represents a policy of
          how, where, and when the agent should run, specified as a cross-cutting
          concern to the code that makes up the agent.
        </p>
<div class="footnotes">
<br><hr style="width:100; text-align:left;margin-left: 0">
<div id="ftn.boost_asio.overview.model.executors.f0" class="footnote"><p><a href="#boost_asio.overview.model.executors.f0" class="para"><sup class="para">[5] </sup></a>
                In Boost.Asio, this kind of executor is called a <a class="link" href="../core/strands.html" title="Strands: Use Threads Without Explicit Locking">strand</a>.
              </p></div>
</div>
</div>
<div class="copyright-footer">Copyright © 2003-2025 Christopher M.
      Kohlhoff<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="child_agents.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../model.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../boost_asio.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="allocators.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
